package java111_2;

import java.util.Arrays;
import java.util.Scanner;

public class Day26 {

    //https://ac.nowcoder.com/acm/problem/230720
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            // 答案只可能为 -1,2,3
            // 如果有相邻的两个字符串则输出 2, 否则如果有隔一个就相同的输出 3, 否则输出 -1
            int res = -1;
            for(int i = 0; i < str.length()-1; i++){
                if(str.charAt(i) == str.charAt(i+1)){
                    res = 2;
                    break;
                } else if(i + 2 < str.length() && str.charAt(i) == str.charAt(i+2)){
                    res = 3;
                }
            }
            System.out.println(res);
        }
    }

    // https://www.nowcoder.com/practice/a2be806a0e5747a088670f5dc62cfa1e?tpId=230&tqId=39763&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            long[] arr = new long[n+1];
            long[] dp = new long[n+1];
            // dp[i] 表示 从前 i 个数中挑选 选出的最大和
            for(int i = 1; i <= n; i++){
                arr[i] = in.nextInt();
            }
            dp[1] = arr[1];
            if(arr.length > 2) dp[2] = Math.max(arr[1], arr[2]);
            for(int i = 3; i <= n; i++){
                dp[i] = Math.max(dp[i-1], dp[i-2] + arr[i]);
            }
            System.out.println(dp[n]);
        }
    }

    //https://ac.nowcoder.com/acm/problem/229310
    public static void main3(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int p = in.nextInt(), res = 0;
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        // 滑动窗口
        for(int left = 0, right = 0; right < n; right++){
            while(arr[right] - arr[left] > 2 * p){
                res = Math.max(res, right - left);
                left++;
            }
        }
        System.out.println(res == 0 ? n : res);
    }
}
